{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a126f4df",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-11-22T11:40:54.007733Z",
     "start_time": "2023-11-22T11:40:49.766500Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pyecharts in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (2.0.3)\n",
      "Requirement already satisfied: jinja2 in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (from pyecharts) (2.11.3)\n",
      "Requirement already satisfied: simplejson in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (from pyecharts) (3.19.1)\n",
      "Requirement already satisfied: prettytable in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (from pyecharts) (3.7.0)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (from jinja2->pyecharts) (2.0.1)\n",
      "Requirement already satisfied: wcwidth in c:\\users\\19678\\anaconda3.1\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c31eaa71",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-11-22T11:44:28.718Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "\u001b[31m   WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
      "\u001b[2m   Use a production WSGI server instead.\u001b[0m\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [22/Nov/2023 19:47:41] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [22/Nov/2023 19:47:45] \"GET /favicon.ico HTTP/1.1\" 404 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask # python 后端与 前端连接的一个框架\n",
    "from jinja2 import Markup, Environment, FileSystemLoader #Jinja2 前端页面展示的框架\n",
    "from pyecharts.globals import CurrentConfig \n",
    "\n",
    "CurrentConfig.GLOBAL_ENV = Environment(loader=FileSystemLoader(\"./templates\"))\n",
    "\n",
    "from pyecharts import options as opts\n",
    "\n",
    "from pyecharts.charts import Bar\n",
    "\n",
    "app = Flask(__name__, static_folder=\"templates\")\n",
    "\n",
    "# 1.找到合适的图表可视化，找到gallery示例代码，测试一下示例代码\n",
    "# 2.准备数据分析结果的参数，替换示例代码的参数\n",
    "# 3.创建制作图的函数\n",
    "def bar_base() -> Bar:\n",
    "    c = (\n",
    "        Bar()\n",
    "        .add_xaxis([\"衬衫\", \"羊毛衫\", \"雪纺衫\", \"裤子\", \"高跟鞋\", \"袜子\"])\n",
    "        .add_yaxis(\"商家A\", [5, 20, 36, 10, 75, 90])\n",
    "        .add_yaxis(\"商家B\", [15, 25, 16, 55, 48, 8])\n",
    "        .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-基本示例\", subtitle=\"我是副标题\"))\n",
    "    )\n",
    "    return c\n",
    "\n",
    "\n",
    "@app.route(\"/\")\n",
    "def index():\n",
    "    c = bar_base()\n",
    "    return Markup(c.render_embed())\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "768d92df",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
